<div class="panel">
	<?php echo form_open('index.php/consignment_takeout/takeout/'.$detail->consignment_id); ?>

		<table class="trans-info">
			<tr>
				<td>Territory</td>
				<td><?=$detail->territory?></td>
			</tr>
			<tr>
				<td>Tanggal Konsinyasi</td>
				<td><?php $tgl = $detail->consignment_date; $tgl = explode(" ", $tgl); echo $tgl[0];?></td>
			</tr>
			<tr>
				<td>Termin Konsinyasi</td>
				<td><?=$detail->term_day?> hari</td>
			</tr>
			<tr>
				<td>Jatuh Tempo</td>
				<td>
					<?php
						$date = strtotime(date("Y-m-d", strtotime($tgl[0])) . " +".$detail->term_day." day");
						echo date('d-m-Y', $date);
					?>
				</td>
			</tr>


			<tr>
				<td>Sales</td>
				<td><?=$detail->user_id?> | <?=$detail->user_name?> | <?=$detail->user_group_caption?></td>
			</tr>
			<tr>
				<td>Channel</td>
				<td><?=$detail->channel?> | <?=$detail->territory_name?></td>
			</tr>
			<tr>
				<td>Status</td>
				<td><?php if($detail->istatus == 1) {echo "Open";} else {echo "Closed";} ?></td>
			</tr>
		</table>

		<table class="item-list">
			<thead>
				<tr>
					<th width="32px" class="nomor"><input type="checkbox" id="tickAll" onChange="ticks()"/></th>
					<th width="">ICCID</th>
					<th>Item Name</th>
					<th>Item Group</th>
					<th>Harga</th>
				</tr>
			</thead>
			<tbody>
				<?php 
					foreach ($items as $item) : 
						if ($item->istatus == 3) { ?>
							<tr id="row_<?=$item->detail_id?>" bgcolor="#FF0000">
				<?php } elseif ($item->istatus == 2){ ?>
							<tr id="row_<?=$item->detail_id?>" style="color: #0000ff !important;">
				<?php } else { ?>
							<tr id="row_<?=$item->detail_id?>">
				<?php } ?>

					<!-- <tr id="row_<?=$item->detail_id?>"> -->
						<input type="hidden" value="<?=$item->detail_id?>" name="detail_id[]" class="item">
						<td width="32px" class="nomor">
							<input type="checkbox" id="item_<?=$item->detail_id?>" onchange="changeStatus(<?=$item->detail_id?>)" >
							<input type="hidden" name="status[]" class="status_<?=$item->detail_id?>" value="0">
						</td>
						<td><input type="hidden" value="<?=$item->iccid?>" name="iccid[]" class="iccid"><?=$item->iccid?></td>
						<td><?=$item->item_name?></td>
						<td><?=$item->item_group_name?></td>
						<td>
							Rp <?php 
								echo number_format($item->price, 2, ',', '.'). '&nbsp;&nbsp;&nbsp;';
								if ($item->istatus == 3) {
									echo '<img src="'.base_url().'file/images/box-share.png"  title="\\\HOREE// item terjual ">';
								} elseif ($item->istatus == 2) {
									echo '<img src="'.base_url().'file/images/box.png" title="Item tidak terjual, kembalikan ke reciept">';
								}
							?>
						</td>
					</tr>
				<?php endforeach; ?>
			
			<tr>
				<td colspan="5">
					<h3>Remarks:</h3>
					<p><?=$detail->remark?></p>
				</td>
			</tr>
			</tbody>
		</table>

		<input type="submit">
	<?php echo form_close();?>
</div>


<script type="text/javascript">
	$(document).ready(function() {
		if ("<?=$detail->istatus?>" != 1) {
			$("input").remove(); $(".nomor").hide();
		};
	});

	function ticks() {
		if($('#tickAll').is('input:checked')) {
			$('input[type="checkbox"]').attr('checked','checked');
			$('input[name="status[]"]').val("1");
		} else {
			$('input[type="checkbox"]').removeAttr('checked');
			$('input[name="status[]"]').val("0");
		}
	}

	function changeStatus(x) {
		// if($('#tickall').is('input:checked')) {
		if($("#item_"+x).is("#item_"+x+':checked')) {
			$(".status_"+x).val("1");
		}
		else {
			$(".status_"+x).val("0");
		}
	}
</script>